﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class frmLapDanhMucPhong : Form
    {
        public frmLapDanhMucPhong()
        {
            InitializeComponent();
        }
        public static string s,ma;
        public static string maphong;
        public static PhongDTO p = new PhongDTO();
        public static PhongBUS bus = new PhongBUS();
        
        public void frmLapDanhMucPhong_Load(object sender, EventArgs e)
        {
            List<PhongDTO> dscn = bus.GetAll();
            dgvDanhmucphong.DataSource = dscn;
        }

        private void btRefresh_Click(object sender, EventArgs e)
        {
            frmLapDanhMucPhong_Load(sender, e);
        }

        private void dgvDanhmucphong_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = 0;
            row = e.RowIndex;
            if (row < 0)
            {
                return;
            }
            ma = dgvDanhmucphong.CurrentRow.Cells[0].Value.ToString();
        }
        private void btthem_Click(object sender, EventArgs e)
        {
            s = "them";
            frmThemPhong b = new frmThemPhong();
            b.ShowDialog();
        }

        private void btsua_Click_1(object sender, EventArgs e)
        {
            s = "sua";
            frmThemPhong b = new frmThemPhong();
             maphong = ma;
            b.ShowDialog();
        }

        private void btxoa_Click(object sender, EventArgs e)
        {
            p.Maphong = ma;
            bool kq = bus.Delete(p);
            if (kq == true)
            {
                MessageBox.Show("Xóa thành công");
                frmLapDanhMucPhong_Load(sender, e);
            }

            else
            {
                MessageBox.Show("Xóa không thành công");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }


    }
}
